import { get } from '@/utils/auth'
import { getMapData } from '@/utils/map'

const getters = {
  token: state => state.user.token,
  avatar: state => state.user.avatar || get('avatar'),
  name: state => state.user.name || get('name'),
  redirectToAfterAuth(state) {
    const authTo = get('auth-to')
    if (typeof authTo === 'undefined') {
      return state.user.authTo
    }
    return authTo
  },
  mapData(state) {
    if (state.map.data.name) {
      return state.map.data
    } else {
      return getMapData()
    }
  },
  mapBackTo: state => state.map.backTo,
  mapType: state => state.map.type,
  open: state => state.nav.open,
  searchName: state => state.search.name,
}

export default getters
